package com.epam.giorgadze.task1.entity.plane_type;

import com.epam.giorgadze.task1.entity.PlaneModel;

import java.util.Comparator;

/**
 * User: Luka
 * Date: 06.02.14
 * Time: 11:30
 */
public class PassengerPlane extends Plane {
    private int numberOfSeats;

    public boolean checkNumberOfSeats(int i) {
        if (i >= 0) {
            return true;
        } else return false;
    }

    public PassengerPlane() {
    }

    public PassengerPlane(PlaneModel model, double travelingDistance, double fuelConsumption, double price, double lifespan, int numberOfSeats) {
        super(model, travelingDistance, fuelConsumption, price, lifespan);
        if (checkNumberOfSeats(numberOfSeats)) this.numberOfSeats = numberOfSeats;
    }

    public int getNumberOfSeats() {
        return numberOfSeats;
    }

    public void setNumberOfSeats(int numberOfSeats) {
        if (checkNumberOfSeats(numberOfSeats)) this.numberOfSeats = numberOfSeats;
    }

    public static class NumberOfSeatsComparator implements Comparator<PassengerPlane> {
        public static final Comparator<PassengerPlane> NUMBER_OF_SEATS_ORDER = new NumberOfSeatsComparator();

        public int compare(PassengerPlane p1, PassengerPlane p2) {
            return Integer.compare(p1.getNumberOfSeats(), p2.getNumberOfSeats());
        }
    }

    @Override
    public String toString() {
        return "\nPassengerPlane" +
                "model: " + this.getModel() +
                ", traveling distance = " +  String.format("%8.3f", this.getTravelingDistance()) +
                ", fuel consumption = " +  String.format("%8.3f", this.getFuelConsumption()) +
                ", price = " +  String.format("%8.3f", this.getPrice()) +
                ", lifespan = " +  String.format("%8.3f", this.getLifespan()) +
                ", numberOfSeats =" + numberOfSeats;
    }
}
